package com.project.srtp.common.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 曹行阳
 * @version 0.1
 * @date 2025/3/25 12:59
 */
@Configuration
public class BloomFilterConfig {
    @Autowired
    private RedissonClient redissonClient;

    @Bean
    public RBloomFilter<String> usernameBloomFilter() {
        RBloomFilter<String> bloomFilter = redissonClient.getBloomFilter("username:bloom-filter");
        // 初始化布隆过滤器（预期元素数量1千万，误判率0.1%）
        bloomFilter.tryInit(10_000_000L, 0.001);
        return bloomFilter;
    }
}
